package com.jie.server.common.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.jie.server.modules.system.entity.AreaEntity;
import com.jie.server.modules.system.entity.Dept;
import com.jie.server.modules.system.entity.Menu;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description Treeselect树结构实体类
 * @author xiaojie
 * @since: 2024/12/12 0012
 */
@Data
public class TreeSelect implements Serializable {

    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    /**
     * 菜单构造函数
     * @param menu
     */
    public TreeSelect(Menu menu) {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    /**
     * 部门构造函数
     * @param dept
     */
    public TreeSelect(Dept dept) {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    /**
     * 行政区划构造函数
     * @param areaEntity
     */
    public TreeSelect(AreaEntity areaEntity) {
        this.id = areaEntity.getAreaId();
        this.label = areaEntity.getName();
        this.children = areaEntity.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

}
